package com.guanyong.www.maoyanDemo;

import java.sql.*;

/**
 * Created by Administrator on 2017/9/12 0012.
 */
public class MySQLConnect {
    public static final String DBDRIVER = "com.mysql.jdbc.Driver";
    //定义MySQL数据库的连接地址
//    public static final String DBURL = "jdbc:mysql://101.201.122.99:3306/db_maoyan1?characterEncoding=utf8&useSSL=true";
//    public static final String DBURL = "jdbc:mysql://101.201.122.99:3306/db_inside?characterEncoding=utf8&useSSL=true";
    public static final String DBURL = "jdbc:mysql://120.92.118.22:3306/db_inside?characterEncoding=utf8&useSSL=true";
    //MySQL数据库的连接用户名和连接密码
    public static final String DBUSER = "root";
    public static final String DBPASS = "123456";
    private static MySQLConnect mySQLConnect=new MySQLConnect();
    private Connection conn;

    private MySQLConnect(){
        try {
            conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection(){
        return mySQLConnect.conn;
    }


    public static void close(ResultSet rs, PreparedStatement pstmt, Connection conn){
        try {
            rs.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        try {
            pstmt.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        try {
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}